<template>
  <div class="activity">
    <div class="activity-item" v-for="(item,index) in title" :key="index">
      <p class="activity-item__title">
        <img
          src="https://fast-learn.oss-cn-hangzhou.aliyuncs.com/tb/activityItemTitle.svg"
          class="activity-item__title__img"
          alt="年货节"
        />
        <span class="activity-item__title__detail">{{item.title}}</span>
      </p>
      <div class="activity-item__content">
        <div
          class="activity-item__content__goods"
          v-for="(goods, index) in data[index]"
          :key="index"
        >
          <div class="activity-item__content__goods__picture">
            <img :src="goods.imageUrl"  class="activity-item__content__goods__picture__img"/>
            <div
              v-if="goods.price !== undefined"
              class="activity-item__content__goods__price"
            >
              ￥{{ goods.price }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  data () {
    return {
      title: [
        { title: '聚划算' },
        { title: '直播' },
        { title: '有好货' },
        { title: '菜菜' }
      ],
      data: {}
    }
  },
  computed: {
    ...mapGetters(['homeList'])
  },
  watch: {
    'homeList.data.seascape': {
      immediate: true,
      handler (val) {
        const Arr = []
        for (let i = 0; i < val.length; i += 2) {
          Arr.push(val.slice(i, i + 2))
        }
        const newArr = Arr

        this.data = newArr
        console.log(this.data)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.activity {
  width: 714px;
  height: 366px;
  background: #ffffff;
  border-radius: 24px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  .activity-item {
      width: 350px;
      height: 169px;
      box-sizing: border-box;

    &__title {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding-left: 12px;
      padding-top: 16px;
      &__img {
        width: 83px;
        height: 36px;
      }
      &__detail {
        font-size: 28px;
        color: #545454;
        letter-spacing: 0;
        margin-left: 8px;
        font-weight: 700;

      }
    }

    &__content {
      width: 365px;
      height: 169px;
      display: flex;
      justify-content: center;
      align-items: center;
      &__goods {

        &__picture{
            &__img{
              width: 140px;
              height: auto;
            }
        }
      }
    }
  }
}
</style>
